index_app.controller("saving_details_list", function ($scope,$http) {

	var grid_selector = "#grid-table";
	var pager_selector = "#grid-pager";


	$(window).on('resize.jqGrid', function() {
		$(grid_selector).jqGrid('setGridWidth', $(".page-content").width());
	});
     $http.post("savingDetail/getSumTotal").then(function(response){
        	//数据源
        	$scope.sumTotal = response.data;
     });
	jQuery(grid_selector).jqGrid('aceInit', pager_selector, {
		url:"savingDetail/listSavingDetail",
		datatype : "json",
		colNames : ['','ID', '日期','操作类型','会员号','会员姓名', '金额','操作员'],
		colModel : [
		            {name:'myac',hidden:true},
		            {name:'saveKey',index:'saveKey', width:60,hidden:true},
		                {name:'date',index:'date', width:60},
		            {name:'type',index:'type', width:60},
		            {name:'vipNum',index:'vipNum', width:60},
		             {name:'vipName',index:'vipName', width:60},
		             {name:'amount',index:'amount', width:60},
		            {name:'operatorNum.usrName',index:'operatorNum', width:60 },
		            ],
		            sortable:true,
		            sortname:'saveKey',
		            sortorder:'asc',
		            caption : "<i class='menu-icon fa fa-globe white'></i>存款明细"
	});
	jQuery(grid_selector).jqGrid('aceNavGrid', pager_selector);
	//});
 $scope.refresh = function(){
        $("#vipNum").val("");
        $("#startDate").val("");
        $("#endDate").val("");
            $(grid_selector).jqGrid('setGridParam',{
                              url:"savingDetail/listSavingDetail",
                              datatype:'json',
                               page:1
                        }).trigger("reloadGrid");
        }
	//查找事件
    $scope.searchByVipNum = function(){
        $(grid_selector).jqGrid('setGridParam',{
              url:"savingDetail/searchSelf?field=VipNum&fieldValue="+$("#vipNum").val(),
              datatype:'json',
               page:1
        }).trigger("reloadGrid");
    }
     $scope.isExport = false;
    $scope.searchTime = function(){
        if(!checkEndTime($scope.startDate,$scope.endDate)){
            $scope.title = "警告";
            $scope.toolTip = "开始时间小于结束时间，请重新选择";
            toolTipDialog();
        } else {
            console.log($scope.startDate);
            $scope.isExport = true;
            $(grid_selector).jqGrid('setGridParam',{
                  url:"savingDetail/searchDate?startDate="+$scope.startDate+"&endDate="+$scope.endDate,
                  datatype:'json',
                  page:1
            }).trigger("reloadGrid");
            toExcel();
        }
    }
    function getRootPath() {
             var strFullPath = window.document.location.href;
             var strPath = window.document.location.pathname;
             var pos = strFullPath.indexOf(strPath);
             var prePath = strFullPath.substring(0, pos);
             var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1);
             return (prePath + postPath);
     }

     function toExcel(){
        $scope.exportExcel = function(){
            $scope.actionStr = "/savingDetail/toDcExcel?startDate="+$scope.startDate+"&endDate="+$scope.endDate;
            $("#formExcel").attr("action", $scope.actionStr);
        }
     }

    function checkEndTime(startTime,endTime){
        $scope.start=new Date(startTime.replace("-", "/").replace("-", "/"));
        $scope.end=new Date(endTime.replace("-", "/").replace("-", "/"));

        if($scope.end < $scope.start){
            return false;
        }
        return true;
    }
function toolTipDialog(){
    		easyDialog.open({
    			container : {
    				header : $scope.title,
    				content : $scope.toolTip,
    				yesFn : $scope.toolFn,
    				noFn : false
    			},
    			fixed : false
    		});
    	}
    	//弹窗中确定按钮事件
    	$scope.toolFn = function(){
    		return true;
    	}

    	/*$('#typeSelect').change(function(){
    	    $scope.selectedVal=$(this).children('option:selected').val();

    	    $scope.type="Type";
    	    if($scope.selectedVal == "类别"){
    	        $scope.type = "";
    	    }
    	     console.log($scope.type);
            $("#grid-table").jqGrid('setGridParam',{
                 url:"savingDetail/searchSelf?field="+$scope.type+"&fieldValue="+$scope.selectedVal,
                 datatype:'json',
                  page:1
             }).trigger("reloadGrid");
        });*/
})


